<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { RouterView } from 'vue-router'
import router from '@/router';
import FingerIcon from '@/icon/finger.vue';
import NormIcon from '@/icon/norm.vue'
import GuideIcon from '@/icon/guide.vue'


const navs = [
  {
    id: '1',
    title: '指导原则',
    route: '/home/guide',
    icon: GuideIcon,
    iconSize: 24
  }, {
    id: '2',
    title: '规范附录',
    route: '/home/norm',
    icon: NormIcon,
    iconSize: 28
  }, {
    id: '3',
    title: '审查指南',
    route: '/home/finger',
    icon: FingerIcon,
    iconSize: 28
  }
]

const activeNavId = ref('1')

onMounted(() => {
  for (const i of navs) {
    if (location.hash === ('#' + i.route)) {
      activeNavId.value = i.id
      break
    }
  }
})

const navTo = (item: any) => {
  // console.log(item);
  activeNavId.value = item.id
  router.replace(item.route)
}
</script>

<template>
  <div class="home">
    <div class="pages">
      <RouterView></RouterView>
    </div>
    <div class="nav">
      <div class="item" v-for="(n, i) in navs" :key="i" @click="navTo(n)">
        <div class="icon">
          <component :is="n.icon" :size="n.iconSize" :color="activeNavId === n.id ? '#00bd7e' : '#000000'"></component>
        </div>
        <div class="title" :style="activeNavId === n.id ? 'color: #00bd7e' : ''">
          {{ n.title }}
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.home {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;

  .pages {
    flex-grow: 1;
    // border: 1px solid red;
    overflow-y: auto;
  }

  .nav {
    border-top: 1px solid #d8d8d8;
    display: flex;
    flex-direction: row;

    .item {
      // border: 1px solid green;
      flex-grow: 1;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      padding: 8px 0;

      .icon {
        width: 28px;
        height: 28px;
        display: flex;
        justify-content: center;
        align-items: center;
      }

      .title {
        font-size: 0.8em;
      }
    }
  }
}
</style>
